package com.tedu.webDemo.controller;

import java.util.ArrayList;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller//@controller返回jsp,
//@restController返回json
public class ItemController {
	@RequestMapping("/list")
	//http://localhost:8080/list
	//把几个商品显示在浏览器上
	public ModelAndView list() {
		//创建modelAndView
		//显示WEB-INF/jsp/item.jsp
		//applicaiton.properties中已经配置WEB-INF/jsp
		//和.jsp
		String viewName="item";
		ModelAndView modelAndView=
				new ModelAndView(viewName);
		//创建集合
		ArrayList<Item> itemList=new ArrayList<Item>();
		//创建两个商品
		Item item1=new Item(80, "mate10");
		Item item2=new Item(90, "thinkpad");
		//把商品放到集合中
		itemList.add(item1);
		itemList.add(item2);
		//把集合放到jsp中
		modelAndView.addObject("list", itemList);
		return modelAndView;
	}

}
